package com.luanye.enjoy.consumer;

import com.alibaba.fastjson.JSON;
import com.luanye.enjoy.dto.SmsDTO;
import com.luanye.enjoy.service.TxSmsService;
import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import static com.luanye.enjoy.constants.MQConst.SMS_QUEUE;

@Component
@RabbitListener(queues = SMS_QUEUE)
@AllArgsConstructor
public class SmsConsumer {


    private final TxSmsService txSmsService;

    @RabbitHandler
    public void sendCode(byte[] data){
        SmsDTO dto = JSON.parseObject(new String(data), SmsDTO.class);
        txSmsService.sendSmsCode(dto.getPhone(), dto.getParams(), dto.getTemplateId());
    }
}
